#include "stdio.h"
#include "stdlib.h"


#define MAXSIZE 100
typedef int DataType;

typedef struct {
    DataType *base;
    DataType *top;
    int size;
} SqStack;

int InitStack(SqStack *S) {
    S->base = malloc(sizeof(DataType) * MAXSIZE);
    if (S->base) {
        return 0;
    }
    S->top = S->base;
    S->size = MAXSIZE;
    return 0;
}

int StackEmpty(SqStack S) {
    if (S.top == S.base)
        return 1;
    return 0;
}

int StackLength(SqStack S) {
    return S.top - S.base;
}


int ClearStack(SqStack *S) {
    S->top = S->base;
    return 0;
}

int DestroyStack(SqStack *S) {
    free(S->base);
    S->base = NULL;
    S->top = NULL;
    S->size = 0;
    return 0;
}

int PushStack(SqStack *S, DataType x) {
    if (S->top - S->base == S->size) {
        return 1;
    }
    *S->top = x;
    S->top++;
    return 0;
}

int PopStack(SqStack *S, DataType *x) {
    if (S->top == S->base) {
        return 1;
    }
    --S->top;
    *x = *S->top;
    return 0;
}

int GetStack(SqStack S, DataType *x) {
    if (S.top == S.base) {
        return 1;
    }
    *x = *(S.top - 1);
    return 0;
}



























